source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-361.rds.xz")
summary(model)
SOM of size 5x5 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 94881 objects.
Mean distance to the closest unit in the map: 0.214.
plot(model, type="changes")
df <- mpr.load_data("datos_mes.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:94881 Length:94881 Min. : 1.000 Min. :-53.0
Class :character Class :character 1st Qu.: 4.000 1st Qu.:148.0
Mode :character Mode :character Median : 6.000 Median :198.0
Mean : 6.497 Mean :200.2
3rd Qu.: 9.000 3rd Qu.:255.0
Max. :12.000 Max. :403.0
tmin precip nevada prof_nieve
Min. :-121.00 Min. : 0.00 Min. :0.000000 Min. : 0.000
1st Qu.: 53.00 1st Qu.: 3.00 1st Qu.:0.000000 1st Qu.: 0.000
Median : 98.00 Median : 10.00 Median :0.000000 Median : 0.000
Mean : 98.86 Mean : 16.25 Mean :0.000295 Mean : 0.467
3rd Qu.: 148.00 3rd Qu.: 22.00 3rd Qu.:0.000000 3rd Qu.: 0.000
Max. : 254.00 Max. :422.00 Max. :6.000000 Max. :1834.000
longitud latitud altitud
Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:38.28 1st Qu.: -5.6417 1st Qu.: 42.0
Median :40.82 Median : -3.4500 Median : 247.0
Mean :39.66 Mean : -3.4350 Mean : 418.5
3rd Qu.:42.08 3rd Qu.: 0.4914 3rd Qu.: 656.0
Max. :43.57 Max. : 4.2156 Max. :2535.0
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
901 4369 6277 6830 5376 528 2168 3800 5861 6738 2442 4149 5627 5782 6624 463
17 18 19 20 21 22 23 24 25
1060 3111 5165 4635 59 1116 2114 3322 6364
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 5*5;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("tmax", "tmin", "precip")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
tmax tmin precip
[1,] 0.7501526 0.7047923 -0.7143514
[2,] 0.5717444 0.7352300 0.2673274
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
tmax precip tmin
0.9701458 0.9663628 0.9631780
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.: 2.000 1st Qu.:113.0 1st Qu.: 21.00 1st Qu.: 6.00
Median : 4.000 Median :143.0 Median : 48.00 Median : 17.00
Mean : 5.816 Mean :139.2 Mean : 45.91 Mean : 24.08
3rd Qu.:11.000 3rd Qu.:168.0 3rd Qu.: 71.00 3rd Qu.: 35.00
Max. :12.000 Max. :336.0 Max. : 219.00 Max. :174.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.000 Min. :27.82 Min. :-17.8889
1st Qu.:0.000000 1st Qu.: 0.000 1st Qu.:40.07 1st Qu.: -5.3456
Median :0.000000 Median : 0.000 Median :41.42 Median : -2.9056
Mean :0.000654 Mean : 1.009 Mean :40.77 Mean : -2.8506
3rd Qu.:0.000000 3rd Qu.: 0.000 3rd Qu.:42.44 3rd Qu.: 0.4942
Max. :6.000000 Max. :1834.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 85.0
Median : 445.0
Mean : 561.3
3rd Qu.: 785.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 41.0 Min. : 0.000 Min. :0
1st Qu.: 5.000 1st Qu.:214.0 1st Qu.:110.0 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :248.0 Median :142.0 Median : 7.000 Median :0
Mean : 7.057 Mean :250.5 Mean :142.5 Mean : 9.563 Mean :0
3rd Qu.: 9.000 3rd Qu.:285.0 3rd Qu.:172.0 3rd Qu.:15.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :62.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.26 1st Qu.: -5.8728 1st Qu.: 32.0
Median : 0.00000 Median :39.95 Median : -3.6325 Median : 87.0
Mean : 0.00935 Mean :38.75 Mean : -3.9125 Mean : 300.9
3rd Qu.: 0.00000 3rd Qu.:41.65 3rd Qu.: 0.4731 3rd Qu.: 541.0
Max. :38.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11.0 Min. :-27.00 Min. :175.0 Min. :0
1st Qu.: 2.000 1st Qu.:116.0 1st Qu.: 63.00 1st Qu.:186.0 1st Qu.:0
Median : 8.000 Median :136.0 Median : 80.00 Median :206.0 Median :0
Mean : 6.763 Mean :153.0 Mean : 86.95 Mean :221.1 Mean :0
3rd Qu.:11.000 3rd Qu.:159.5 3rd Qu.: 99.00 3rd Qu.:232.5 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00 Min. :28.31 Min. :-16.499 Min. : 4.00
1st Qu.: 0.00 1st Qu.:40.72 1st Qu.: -8.624 1st Qu.: 86.55
Median : 0.00 Median :42.24 Median : -8.411 Median : 261.00
Mean : 10.34 Mean :40.71 Mean : -7.114 Mean : 416.47
3rd Qu.: 0.00 3rd Qu.:42.89 3rd Qu.: -5.600 3rd Qu.: 370.00
Max. :607.00 Max. :43.36 Max. : 2.825 Max. :2371.00
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.: 2.000 1st Qu.:112.0 1st Qu.: 19.00 1st Qu.: 6.00
Median : 4.000 Median :142.0 Median : 45.00 Median : 15.00
Mean : 5.688 Mean :137.2 Mean : 42.63 Mean : 19.97
3rd Qu.:11.000 3rd Qu.:166.0 3rd Qu.: 67.00 3rd Qu.: 31.00
Max. :12.000 Max. :263.0 Max. : 159.00 Max. :126.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.000 Min. :27.82 Min. :-17.8889
1st Qu.:0.000000 1st Qu.: 0.000 1st Qu.:40.07 1st Qu.: -4.8500
Median :0.000000 Median : 0.000 Median :41.42 Median : -2.7331
Mean :0.000696 Mean : 1.036 Mean :40.74 Mean : -2.7452
3rd Qu.:0.000000 3rd Qu.: 0.000 3rd Qu.:42.38 3rd Qu.: 0.5356
Max. :6.000000 Max. :1834.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 90.0
Median : 513.0
Mean : 581.6
3rd Qu.: 790.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 41.0 Min. : 0.000 Min. :0
1st Qu.: 5.000 1st Qu.:214.0 1st Qu.:110.0 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :248.0 Median :142.0 Median : 7.000 Median :0
Mean : 7.057 Mean :250.5 Mean :142.5 Mean : 9.563 Mean :0
3rd Qu.: 9.000 3rd Qu.:285.0 3rd Qu.:172.0 3rd Qu.:15.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :62.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.26 1st Qu.: -5.8728 1st Qu.: 32.0
Median : 0.00000 Median :39.95 Median : -3.6325 Median : 87.0
Mean : 0.00935 Mean :38.75 Mean : -3.9125 Mean : 300.9
3rd Qu.: 0.00000 3rd Qu.:41.65 3rd Qu.: 0.4731 3rd Qu.: 541.0
Max. :38.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. : 53.00 Min. :0
1st Qu.: 4.000 1st Qu.:133.0 1st Qu.: 67.00 1st Qu.: 70.00 1st Qu.:0
Median :10.000 Median :169.0 Median : 97.00 Median : 81.00 Median :0
Mean : 7.776 Mean :169.3 Mean : 95.84 Mean : 86.77 Mean :0
3rd Qu.:11.000 3rd Qu.:203.0 3rd Qu.:125.00 3rd Qu.: 98.00 3rd Qu.:0
Max. :12.000 Max. :336.0 Max. :219.00 Max. :174.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.78 1st Qu.: -8.411 1st Qu.: 27.1
Median : 0.0000 Median :42.43 Median : -4.049 Median : 98.0
Mean : 0.5991 Mean :41.13 Mean : -4.455 Mean : 250.9
3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -1.787 3rd Qu.: 261.0
Max. :892.0000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11.0 Min. :-27.00 Min. :175.0 Min. :0
1st Qu.: 2.000 1st Qu.:116.0 1st Qu.: 63.00 1st Qu.:186.0 1st Qu.:0
Median : 8.000 Median :136.0 Median : 80.00 Median :206.0 Median :0
Mean : 6.763 Mean :153.0 Mean : 86.95 Mean :221.1 Mean :0
3rd Qu.:11.000 3rd Qu.:159.5 3rd Qu.: 99.00 3rd Qu.:232.5 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00 Min. :28.31 Min. :-16.499 Min. : 4.00
1st Qu.: 0.00 1st Qu.:40.72 1st Qu.: -8.624 1st Qu.: 86.55
Median : 0.00 Median :42.24 Median : -8.411 Median : 261.00
Mean : 10.34 Mean :40.71 Mean : -7.114 Mean : 416.47
3rd Qu.: 0.00 3rd Qu.:42.89 3rd Qu.: -5.600 3rd Qu.: 370.00
Max. :607.00 Max. :43.36 Max. : 2.825 Max. :2371.00
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.: 2.000 1st Qu.:107.0 1st Qu.: 11.00 1st Qu.: 4.00
Median : 3.000 Median :138.0 Median : 36.00 Median : 9.00
Mean : 5.421 Mean :132.8 Mean : 32.14 Mean :10.34
3rd Qu.:11.000 3rd Qu.:162.0 3rd Qu.: 57.00 3rd Qu.:16.00
Max. :12.000 Max. :250.0 Max. : 105.00 Max. :45.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :28.31 Min. :-16.4992
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:39.95 1st Qu.: -4.5353
Median :0.000000 Median : 0.0000 Median :41.11 Median : -2.3308
Mean :0.001007 Mean : 0.6689 Mean :40.54 Mean : -2.4561
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:41.98 3rd Qu.: 0.5831
Max. :6.000000 Max. :1494.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 143.0
Median : 582.0
Mean : 618.9
3rd Qu.: 846.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 41.0 Min. : 0.000 Min. :0
1st Qu.: 5.000 1st Qu.:214.0 1st Qu.:110.0 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :248.0 Median :142.0 Median : 7.000 Median :0
Mean : 7.057 Mean :250.5 Mean :142.5 Mean : 9.563 Mean :0
3rd Qu.: 9.000 3rd Qu.:285.0 3rd Qu.:172.0 3rd Qu.:15.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :62.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.26 1st Qu.: -5.8728 1st Qu.: 32.0
Median : 0.00000 Median :39.95 Median : -3.6325 Median : 87.0
Mean : 0.00935 Mean :38.75 Mean : -3.9125 Mean : 300.9
3rd Qu.: 0.00000 3rd Qu.:41.65 3rd Qu.: 0.4731 3rd Qu.: 541.0
Max. :38.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-47.0 Min. :-115.00 Min. : 23.00
1st Qu.: 3.000 1st Qu.:125.0 1st Qu.: 46.00 1st Qu.: 32.00
Median : 5.000 Median :151.0 Median : 69.00 Median : 39.00
Mean : 6.285 Mean :147.2 Mean : 66.14 Mean : 41.55
3rd Qu.:11.000 3rd Qu.:176.0 3rd Qu.: 91.00 3rd Qu.: 48.00
Max. :12.000 Max. :263.0 Max. : 159.00 Max. :126.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.8889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.63 1st Qu.: -5.8728
Median :0 Median : 0.000 Median :42.24 Median : -3.7892
Mean :0 Mean : 1.858 Mean :41.20 Mean : -3.3937
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:43.30 3rd Qu.: 0.3664
Max. :0 Max. :1834.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1
1st Qu.: 58
Median : 251
Mean : 498
3rd Qu.: 632
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. : 53.00 Min. :0
1st Qu.: 4.000 1st Qu.:133.0 1st Qu.: 67.00 1st Qu.: 70.00 1st Qu.:0
Median :10.000 Median :169.0 Median : 97.00 Median : 81.00 Median :0
Mean : 7.776 Mean :169.3 Mean : 95.84 Mean : 86.77 Mean :0
3rd Qu.:11.000 3rd Qu.:203.0 3rd Qu.:125.00 3rd Qu.: 98.00 3rd Qu.:0
Max. :12.000 Max. :336.0 Max. :219.00 Max. :174.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.78 1st Qu.: -8.411 1st Qu.: 27.1
Median : 0.0000 Median :42.43 Median : -4.049 Median : 98.0
Mean : 0.5991 Mean :41.13 Mean : -4.455 Mean : 250.9
3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -1.787 3rd Qu.: 261.0
Max. :892.0000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11.0 Min. :-27.00 Min. :175.0 Min. :0
1st Qu.: 2.000 1st Qu.:116.0 1st Qu.: 63.00 1st Qu.:186.0 1st Qu.:0
Median : 8.000 Median :136.0 Median : 80.00 Median :206.0 Median :0
Mean : 6.763 Mean :153.0 Mean : 86.95 Mean :221.1 Mean :0
3rd Qu.:11.000 3rd Qu.:159.5 3rd Qu.: 99.00 3rd Qu.:232.5 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00 Min. :28.31 Min. :-16.499 Min. : 4.00
1st Qu.: 0.00 1st Qu.:40.72 1st Qu.: -8.624 1st Qu.: 86.55
Median : 0.00 Median :42.24 Median : -8.411 Median : 261.00
Mean : 10.34 Mean :40.71 Mean : -7.114 Mean : 416.47
3rd Qu.: 0.00 3rd Qu.:42.89 3rd Qu.: -5.600 3rd Qu.: 370.00
Max. :607.00 Max. :43.36 Max. : 2.825 Max. :2371.00
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.: 2.000 1st Qu.:107.0 1st Qu.: 11.00 1st Qu.: 4.00
Median : 3.000 Median :138.0 Median : 36.00 Median : 9.00
Mean : 5.421 Mean :132.8 Mean : 32.14 Mean :10.34
3rd Qu.:11.000 3rd Qu.:162.0 3rd Qu.: 57.00 3rd Qu.:16.00
Max. :12.000 Max. :250.0 Max. : 105.00 Max. :45.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :28.31 Min. :-16.4992
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:39.95 1st Qu.: -4.5353
Median :0.000000 Median : 0.0000 Median :41.11 Median : -2.3308
Mean :0.001007 Mean : 0.6689 Mean :40.54 Mean : -2.4561
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:41.98 3rd Qu.: 0.5831
Max. :6.000000 Max. :1494.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 143.0
Median : 582.0
Mean : 618.9
3rd Qu.: 846.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 41.0 Min. : 0.0 Min. :0
1st Qu.: 5.000 1st Qu.:200.0 1st Qu.: 97.0 1st Qu.: 4.0 1st Qu.:0
Median : 6.000 Median :222.0 Median :118.0 Median :10.0 Median :0
Mean : 6.746 Mean :221.4 Mean :120.5 Mean :12.3 Mean :0
3rd Qu.: 9.000 3rd Qu.:243.0 3rd Qu.:143.0 3rd Qu.:19.0 3rd Qu.:0
Max. :12.000 Max. :352.0 Max. :220.0 Max. :62.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.26 1st Qu.: -6.0442 1st Qu.: 32.0
Median : 0.00000 Median :40.47 Median : -3.7642 Median : 90.0
Mean : 0.01518 Mean :38.92 Mean : -4.2110 Mean : 325.3
3rd Qu.: 0.00000 3rd Qu.:42.05 3rd Qu.: 0.3664 3rd Qu.: 567.0
Max. :38.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-47.0 Min. :-115.00 Min. : 23.00
1st Qu.: 3.000 1st Qu.:125.0 1st Qu.: 46.00 1st Qu.: 32.00
Median : 5.000 Median :151.0 Median : 69.00 Median : 39.00
Mean : 6.285 Mean :147.2 Mean : 66.14 Mean : 41.55
3rd Qu.:11.000 3rd Qu.:176.0 3rd Qu.: 91.00 3rd Qu.: 48.00
Max. :12.000 Max. :263.0 Max. : 159.00 Max. :126.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.8889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.63 1st Qu.: -5.8728
Median :0 Median : 0.000 Median :42.24 Median : -3.7892
Mean :0 Mean : 1.858 Mean :41.20 Mean : -3.3937
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:43.30 3rd Qu.: 0.3664
Max. :0 Max. :1834.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1
1st Qu.: 58
Median : 251
Mean : 498
3rd Qu.: 632
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 2.00 Min. :228.0 Min. : 96.0 Min. : 0.000 Min. :0
1st Qu.: 7.00 1st Qu.:276.0 1st Qu.:156.0 1st Qu.: 0.000 1st Qu.:0
Median : 8.00 Median :294.0 Median :179.0 Median : 2.000 Median :0
Mean : 7.55 Mean :296.7 Mean :177.3 Mean : 5.225 Mean :0
3rd Qu.: 8.00 3rd Qu.:315.0 3rd Qu.:198.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.00 Max. :403.0 Max. :254.0 Max. :37.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.00e+00 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:0.00e+00 1st Qu.:37.26 1st Qu.: -5.6156 1st Qu.: 32.0
Median :0.00e+00 Median :39.49 Median : -2.9553 Median : 87.0
Mean :9.95e-05 Mean :38.49 Mean : -3.4392 Mean : 262.2
3rd Qu.:0.00e+00 3rd Qu.:41.15 3rd Qu.: 0.4942 3rd Qu.: 540.0
Max. :2.00e+00 Max. :43.56 Max. : 4.2156 Max. :1894.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. : 53.00 Min. :0
1st Qu.: 4.000 1st Qu.:133.0 1st Qu.: 67.00 1st Qu.: 70.00 1st Qu.:0
Median :10.000 Median :169.0 Median : 97.00 Median : 81.00 Median :0
Mean : 7.776 Mean :169.3 Mean : 95.84 Mean : 86.77 Mean :0
3rd Qu.:11.000 3rd Qu.:203.0 3rd Qu.:125.00 3rd Qu.: 98.00 3rd Qu.:0
Max. :12.000 Max. :336.0 Max. :219.00 Max. :174.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.78 1st Qu.: -8.411 1st Qu.: 27.1
Median : 0.0000 Median :42.43 Median : -4.049 Median : 98.0
Mean : 0.5991 Mean :41.13 Mean : -4.455 Mean : 250.9
3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -1.787 3rd Qu.: 261.0
Max. :892.0000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11.0 Min. :-27.00 Min. :175.0 Min. :0
1st Qu.: 2.000 1st Qu.:116.0 1st Qu.: 63.00 1st Qu.:186.0 1st Qu.:0
Median : 8.000 Median :136.0 Median : 80.00 Median :206.0 Median :0
Mean : 6.763 Mean :153.0 Mean : 86.95 Mean :221.1 Mean :0
3rd Qu.:11.000 3rd Qu.:159.5 3rd Qu.: 99.00 3rd Qu.:232.5 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00 Min. :28.31 Min. :-16.499 Min. : 4.00
1st Qu.: 0.00 1st Qu.:40.72 1st Qu.: -8.624 1st Qu.: 86.55
Median : 0.00 Median :42.24 Median : -8.411 Median : 261.00
Mean : 10.34 Mean :40.71 Mean : -7.114 Mean : 416.47
3rd Qu.: 0.00 3rd Qu.:42.89 3rd Qu.: -5.600 3rd Qu.: 370.00
Max. :607.00 Max. :43.36 Max. : 2.825 Max. :2371.00
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.: 2.000 1st Qu.:107.0 1st Qu.: 11.00 1st Qu.: 4.00
Median : 3.000 Median :138.0 Median : 36.00 Median : 9.00
Mean : 5.421 Mean :132.8 Mean : 32.14 Mean :10.34
3rd Qu.:11.000 3rd Qu.:162.0 3rd Qu.: 57.00 3rd Qu.:16.00
Max. :12.000 Max. :250.0 Max. : 105.00 Max. :45.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :28.31 Min. :-16.4992
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:39.95 1st Qu.: -4.5353
Median :0.000000 Median : 0.0000 Median :41.11 Median : -2.3308
Mean :0.001007 Mean : 0.6689 Mean :40.54 Mean : -2.4561
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:41.98 3rd Qu.: 0.5831
Max. :6.000000 Max. :1494.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 143.0
Median : 582.0
Mean : 618.9
3rd Qu.: 846.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 41.0 Min. : 0.0 Min. :0
1st Qu.: 5.000 1st Qu.:200.0 1st Qu.: 97.0 1st Qu.: 4.0 1st Qu.:0
Median : 6.000 Median :222.0 Median :118.0 Median :10.0 Median :0
Mean : 6.746 Mean :221.4 Mean :120.5 Mean :12.3 Mean :0
3rd Qu.: 9.000 3rd Qu.:243.0 3rd Qu.:143.0 3rd Qu.:19.0 3rd Qu.:0
Max. :12.000 Max. :352.0 Max. :220.0 Max. :62.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.26 1st Qu.: -6.0442 1st Qu.: 32.0
Median : 0.00000 Median :40.47 Median : -3.7642 Median : 90.0
Mean : 0.01518 Mean :38.92 Mean : -4.2110 Mean : 325.3
3rd Qu.: 0.00000 3rd Qu.:42.05 3rd Qu.: 0.3664 3rd Qu.: 567.0
Max. :38.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-47.00 Min. :-115.00 Min. : 45.00
1st Qu.: 2.000 1st Qu.: 8.00 1st Qu.: -49.00 1st Qu.: 54.00
Median : 4.000 Median : 30.00 Median : -27.50 Median : 62.00
Mean : 5.712 Mean : 29.34 Mean : -30.13 Mean : 65.66
3rd Qu.:11.000 3rd Qu.: 51.00 3rd Qu.: -8.00 3rd Qu.: 75.00
Max. :12.000 Max. :104.00 Max. : 24.00 Max. :126.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.: -4.0103
Median :0 Median : 0.00 Median :42.47 Median : 0.7789
Mean :0 Mean : 36.55 Mean :41.53 Mean : -1.1603
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.64 3rd Qu.: 1.2717
Max. :0 Max. :1834.00 Max. :43.31 Max. : 2.4378
altitud
Min. : 42
1st Qu.:1894
Median :2230
Mean :2083
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 46.0 Min. :-39.00 Min. :23.00 Min. :0
1st Qu.: 3.000 1st Qu.:129.0 1st Qu.: 50.00 1st Qu.:32.00 1st Qu.:0
Median : 5.000 Median :152.0 Median : 71.00 Median :38.00 Median :0
Mean : 6.311 Mean :152.4 Mean : 70.42 Mean :40.47 Mean :0
3rd Qu.:11.000 3rd Qu.:177.0 3rd Qu.: 92.00 3rd Qu.:47.00 3rd Qu.:0
Max. :12.000 Max. :263.0 Max. :159.00 Max. :71.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.47 1st Qu.: -5.8792 1st Qu.: 52.0
Median : 0.0000 Median :42.24 Median : -3.7892 Median : 251.0
Mean : 0.3143 Mean :41.19 Mean : -3.4930 Mean : 427.5
3rd Qu.: 0.0000 3rd Qu.:43.30 3rd Qu.: 0.0714 3rd Qu.: 609.0
Max. :666.0000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 2.00 Min. :228.0 Min. : 96.0 Min. : 0.000 Min. :0
1st Qu.: 7.00 1st Qu.:276.0 1st Qu.:156.0 1st Qu.: 0.000 1st Qu.:0
Median : 8.00 Median :294.0 Median :179.0 Median : 2.000 Median :0
Mean : 7.55 Mean :296.7 Mean :177.3 Mean : 5.225 Mean :0
3rd Qu.: 8.00 3rd Qu.:315.0 3rd Qu.:198.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.00 Max. :403.0 Max. :254.0 Max. :37.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.00e+00 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:0.00e+00 1st Qu.:37.26 1st Qu.: -5.6156 1st Qu.: 32.0
Median :0.00e+00 Median :39.49 Median : -2.9553 Median : 87.0
Mean :9.95e-05 Mean :38.49 Mean : -3.4392 Mean : 262.2
3rd Qu.:0.00e+00 3rd Qu.:41.15 3rd Qu.: 0.4942 3rd Qu.: 540.0
Max. :2.00e+00 Max. :43.56 Max. : 4.2156 Max. :1894.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8 Min. :-58.0 Min. :106.0 Min. :0
1st Qu.: 3.000 1st Qu.:119 1st Qu.: 57.0 1st Qu.:114.0 1st Qu.:0
Median :10.000 Median :140 Median : 78.0 Median :124.0 Median :0
Mean : 7.803 Mean :144 Mean : 77.9 Mean :128.1 Mean :0
3rd Qu.:11.000 3rd Qu.:169 3rd Qu.:103.0 3rd Qu.:138.5 3rd Qu.:0
Max. :12.000 Max. :326 Max. :207.0 Max. :174.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.29 1st Qu.: -8.616 1st Qu.: 32.0
Median : 0.000 Median :42.43 Median : -6.949 Median : 251.0
Mean : 2.821 Mean :41.40 Mean : -5.700 Mean : 365.6
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -2.039 3rd Qu.: 370.0
Max. :892.000 Max. :43.57 Max. : 3.035 Max. :2535.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 49.0 Min. :-22.00 Min. : 53.00 Min. :0
1st Qu.: 4.00 1st Qu.:138.8 1st Qu.: 71.00 1st Qu.: 67.00 1st Qu.:0
Median :10.00 Median :176.0 Median :103.00 Median : 77.00 Median :0
Mean : 7.77 Mean :174.7 Mean : 99.65 Mean : 77.98 Mean :0
3rd Qu.:11.00 3rd Qu.:208.0 3rd Qu.:128.00 3rd Qu.: 88.00 3rd Qu.:0
Max. :12.00 Max. :336.0 Max. :219.00 Max. :118.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:39.99 1st Qu.: -8.372 1st Qu.: 27.1
Median : 0.0000 Median :42.38 Median : -3.831 Median : 90.5
Mean : 0.1264 Mean :41.07 Mean : -4.191 Mean : 226.5
3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -1.787 3rd Qu.: 261.0
Max. :45.0000 Max. :43.57 Max. : 4.216 Max. :2519.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11.0 Min. :-27.00 Min. :175.0 Min. :0
1st Qu.: 2.000 1st Qu.:116.0 1st Qu.: 63.00 1st Qu.:186.0 1st Qu.:0
Median : 8.000 Median :136.0 Median : 80.00 Median :206.0 Median :0
Mean : 6.763 Mean :153.0 Mean : 86.95 Mean :221.1 Mean :0
3rd Qu.:11.000 3rd Qu.:159.5 3rd Qu.: 99.00 3rd Qu.:232.5 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00 Min. :28.31 Min. :-16.499 Min. : 4.00
1st Qu.: 0.00 1st Qu.:40.72 1st Qu.: -8.624 1st Qu.: 86.55
Median : 0.00 Median :42.24 Median : -8.411 Median : 261.00
Mean : 10.34 Mean :40.71 Mean : -7.114 Mean : 416.47
3rd Qu.: 0.00 3rd Qu.:42.89 3rd Qu.: -5.600 3rd Qu.: 370.00
Max. :607.00 Max. :43.36 Max. : 2.825 Max. :2371.00
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.0000 Min. : 0.00
1st Qu.: 1.000 1st Qu.: 76.00 1st Qu.: -15.0000 1st Qu.: 6.00
Median : 2.000 Median : 94.00 Median : 3.0000 Median :13.00
Mean : 5.359 Mean : 89.35 Mean : 0.5038 Mean :13.74
3rd Qu.:12.000 3rd Qu.:108.00 3rd Qu.: 19.0000 3rd Qu.:21.00
Max. :12.000 Max. :173.00 Max. : 60.0000 Max. :45.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0.000000 1st Qu.: 0.000 1st Qu.:40.66 1st Qu.: -4.1269
Median :0.000000 Median : 0.000 Median :41.59 Median : -2.6544
Mean :0.002426 Mean : 1.911 Mean :41.00 Mean : -2.6947
3rd Qu.:0.000000 3rd Qu.: 0.000 3rd Qu.:42.36 3rd Qu.: 0.3264
Max. :6.000000 Max. :1494.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 2.0
1st Qu.: 609.0
Median : 790.0
Mean : 938.1
3rd Qu.:1056.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : 74.0 Min. :-40.00 Min. : 0.000
1st Qu.: 2.000 1st Qu.:137.0 1st Qu.: 33.00 1st Qu.: 3.000
Median : 3.000 Median :154.0 Median : 49.00 Median : 8.000
Mean : 5.451 Mean :153.8 Mean : 47.46 Mean : 8.696
3rd Qu.:11.000 3rd Qu.:171.0 3rd Qu.: 64.00 3rd Qu.:13.000
Max. :12.000 Max. :250.0 Max. :105.00 Max. :28.000
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.00000 Min. :28.31 Min. :-16.499
1st Qu.:0.0000000 1st Qu.: 0.00000 1st Qu.:39.47 1st Qu.: -4.535
Median :0.0000000 Median : 0.00000 Median :40.95 Median : -1.885
Mean :0.0003203 Mean : 0.06726 Mean :40.31 Mean : -2.341
3rd Qu.:0.0000000 3rd Qu.: 0.00000 3rd Qu.:41.74 3rd Qu.: 0.595
Max. :2.0000000 Max. :65.00000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 71.0
Median : 405.0
Mean : 464.4
3rd Qu.: 687.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 41.0 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.:199.0 1st Qu.: 96.0 1st Qu.: 3.00 1st Qu.:0
Median : 6.000 Median :220.0 Median :116.0 Median : 9.00 Median :0
Mean : 6.649 Mean :219.7 Mean :118.4 Mean :10.48 Mean :0
3rd Qu.: 9.000 3rd Qu.:241.0 3rd Qu.:139.0 3rd Qu.:17.00 3rd Qu.:0
Max. :12.000 Max. :309.0 Max. :201.0 Max. :31.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1
1st Qu.: 0.00000 1st Qu.:37.18 1st Qu.: -6.0556 1st Qu.: 32
Median : 0.00000 Median :40.38 Median : -3.7892 Median : 90
Mean : 0.01498 Mean :38.82 Mean : -4.3413 Mean : 334
3rd Qu.: 0.00000 3rd Qu.:41.98 3rd Qu.: 0.0714 3rd Qu.: 609
Max. :38.00000 Max. :43.57 Max. : 4.2156 Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-47.00 Min. :-115.00 Min. : 45.00
1st Qu.: 2.000 1st Qu.: 8.00 1st Qu.: -49.00 1st Qu.: 54.00
Median : 4.000 Median : 30.00 Median : -27.50 Median : 62.00
Mean : 5.712 Mean : 29.34 Mean : -30.13 Mean : 65.66
3rd Qu.:11.000 3rd Qu.: 51.00 3rd Qu.: -8.00 3rd Qu.: 75.00
Max. :12.000 Max. :104.00 Max. : 24.00 Max. :126.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.: -4.0103
Median :0 Median : 0.00 Median :42.47 Median : 0.7789
Mean :0 Mean : 36.55 Mean :41.53 Mean : -1.1603
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.64 3rd Qu.: 1.2717
Max. :0 Max. :1834.00 Max. :43.31 Max. : 2.4378
altitud
Min. : 42
1st Qu.:1894
Median :2230
Mean :2083
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 46.0 Min. :-39.00 Min. :23.00 Min. :0
1st Qu.: 3.000 1st Qu.:129.0 1st Qu.: 50.00 1st Qu.:32.00 1st Qu.:0
Median : 5.000 Median :152.0 Median : 71.00 Median :38.00 Median :0
Mean : 6.311 Mean :152.4 Mean : 70.42 Mean :40.47 Mean :0
3rd Qu.:11.000 3rd Qu.:177.0 3rd Qu.: 92.00 3rd Qu.:47.00 3rd Qu.:0
Max. :12.000 Max. :263.0 Max. :159.00 Max. :71.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.47 1st Qu.: -5.8792 1st Qu.: 52.0
Median : 0.0000 Median :42.24 Median : -3.7892 Median : 251.0
Mean : 0.3143 Mean :41.19 Mean : -3.4930 Mean : 427.5
3rd Qu.: 0.0000 3rd Qu.:43.30 3rd Qu.: 0.0714 3rd Qu.: 609.0
Max. :666.0000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 2.00 Min. :228.0 Min. : 96.0 Min. : 0.000 Min. :0
1st Qu.: 7.00 1st Qu.:276.0 1st Qu.:156.0 1st Qu.: 0.000 1st Qu.:0
Median : 8.00 Median :294.0 Median :179.0 Median : 2.000 Median :0
Mean : 7.55 Mean :296.7 Mean :177.3 Mean : 5.225 Mean :0
3rd Qu.: 8.00 3rd Qu.:315.0 3rd Qu.:198.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.00 Max. :403.0 Max. :254.0 Max. :37.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.00e+00 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:0.00e+00 1st Qu.:37.26 1st Qu.: -5.6156 1st Qu.: 32.0
Median :0.00e+00 Median :39.49 Median : -2.9553 Median : 87.0
Mean :9.95e-05 Mean :38.49 Mean : -3.4392 Mean : 262.2
3rd Qu.:0.00e+00 3rd Qu.:41.15 3rd Qu.: 0.4942 3rd Qu.: 540.0
Max. :2.00e+00 Max. :43.56 Max. : 4.2156 Max. :1894.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8 Min. :-58.0 Min. :106.0 Min. :0
1st Qu.: 3.000 1st Qu.:119 1st Qu.: 57.0 1st Qu.:114.0 1st Qu.:0
Median :10.000 Median :140 Median : 78.0 Median :124.0 Median :0
Mean : 7.803 Mean :144 Mean : 77.9 Mean :128.1 Mean :0
3rd Qu.:11.000 3rd Qu.:169 3rd Qu.:103.0 3rd Qu.:138.5 3rd Qu.:0
Max. :12.000 Max. :326 Max. :207.0 Max. :174.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.29 1st Qu.: -8.616 1st Qu.: 32.0
Median : 0.000 Median :42.43 Median : -6.949 Median : 251.0
Mean : 2.821 Mean :41.40 Mean : -5.700 Mean : 365.6
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -2.039 3rd Qu.: 370.0
Max. :892.000 Max. :43.57 Max. : 3.035 Max. :2535.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 49.0 Min. :-22.00 Min. : 53.00 Min. :0
1st Qu.: 4.00 1st Qu.:138.8 1st Qu.: 71.00 1st Qu.: 67.00 1st Qu.:0
Median :10.00 Median :176.0 Median :103.00 Median : 77.00 Median :0
Mean : 7.77 Mean :174.7 Mean : 99.65 Mean : 77.98 Mean :0
3rd Qu.:11.00 3rd Qu.:208.0 3rd Qu.:128.00 3rd Qu.: 88.00 3rd Qu.:0
Max. :12.00 Max. :336.0 Max. :219.00 Max. :118.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:39.99 1st Qu.: -8.372 1st Qu.: 27.1
Median : 0.0000 Median :42.38 Median : -3.831 Median : 90.5
Mean : 0.1264 Mean :41.07 Mean : -4.191 Mean : 226.5
3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -1.787 3rd Qu.: 261.0
Max. :45.0000 Max. :43.57 Max. : 4.216 Max. :2519.0
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11.0 Min. :-27.00 Min. :175.0 Min. :0
1st Qu.: 2.000 1st Qu.:116.0 1st Qu.: 63.00 1st Qu.:186.0 1st Qu.:0
Median : 8.000 Median :136.0 Median : 80.00 Median :206.0 Median :0
Mean : 6.763 Mean :153.0 Mean : 86.95 Mean :221.1 Mean :0
3rd Qu.:11.000 3rd Qu.:159.5 3rd Qu.: 99.00 3rd Qu.:232.5 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00 Min. :28.31 Min. :-16.499 Min. : 4.00
1st Qu.: 0.00 1st Qu.:40.72 1st Qu.: -8.624 1st Qu.: 86.55
Median : 0.00 Median :42.24 Median : -8.411 Median : 261.00
Mean : 10.34 Mean :40.71 Mean : -7.114 Mean : 416.47
3rd Qu.: 0.00 3rd Qu.:42.89 3rd Qu.: -5.600 3rd Qu.: 370.00
Max. :607.00 Max. :43.36 Max. : 2.825 Max. :2371.00
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :196.0 Min. : 90.0 Min. :26.00 Min. :0
1st Qu.: 7.000 1st Qu.:228.0 1st Qu.:137.0 1st Qu.:32.00 1st Qu.:0
Median : 9.000 Median :244.0 Median :150.0 Median :36.00 Median :0
Mean : 8.119 Mean :245.9 Mean :151.3 Mean :37.84 Mean :0
3rd Qu.: 9.000 3rd Qu.:263.0 3rd Qu.:165.0 3rd Qu.:42.00 3rd Qu.:0
Max. :12.000 Max. :352.0 Max. :220.0 Max. :62.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:39.48 1st Qu.: -5.598 1st Qu.: 27.0
Median : 0.00000 Median :41.52 Median : -1.787 Median : 75.5
Mean : 0.01798 Mean :40.42 Mean : -2.376 Mean : 203.4
3rd Qu.: 0.00000 3rd Qu.:42.78 3rd Qu.: 1.397 3rd Qu.: 258.0
Max. :27.00000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)